#!/bin/bash

# wget -O /tmp/clashinstall.sh https://gitee.com/gemilk/image_repo/raw/master/install_clash_core.sh && chmod +x /tmp/clashinstall.sh && /tmp/clashinstall.sh && rm -f /tmp/clashinstall.sh
if [ -d "/usr/share/openclash/core" ]; then
    cd /usr/share/openclash/core
    echo "已进入 /usr/share/openclash/core 目录"
elif [ -d "/etc/openclash/core" ]; then
    cd /etc/openclash/core/
    echo "已进入 /etc/openclash/core/ 目录"
else
    echo "两个目录都不存在，退出脚本"
    exit 1
fi

rm -rf ./*
# dev
wget https://gitee.com/gemilk/image_repo/raw/master/clash-core/dev/clash-linux-armv8.tar.gz
tar -zxvf clash-linux-armv8.tar.gz
rm -f clash-linux-armv8.tar.gz
chmod 777 clash
# pre
wget https://gitee.com/gemilk/image_repo/raw/master/clash-core/pre/clash-linux-arm64-2023.08.17-13-gdcc8d87.gz
gzip -d clash-linux-arm64-2023.08.17-13-gdcc8d87.gz
mv clash-linux-arm64-2023.08.17-13-gdcc8d87 clash_tun
chmod 777 clash_tun
# meta
wget https://gitee.com/gemilk/image_repo/raw/master/clash-core/meta/clash-linux-arm64.tar.gz
tar -zxvf clash-linux-arm64.tar.gz --transform 's/^clash/clash_meta/'
rm -f clash-linux-arm64.tar.gz
chmod 777 clash_meta

chown -R root:root ./*